﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class stu_topUpGold : System.Web.UI.Page
{
    string stuId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("checkStu.aspx");
        stuId = Session["stuId"].ToString();
    }
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        string cardID = tb_cardID.Text;
        string cardPwd = tb_cardPWD.Text;
        db_gold gold = new db_gold();
        string goldNum = gold.selectCardGold(cardID).Tables[0].Rows[0]["gold"].ToString();
        if (!gold.cardID_pwd(cardID, cardPwd))
        {
            Response.Write("<script language=javascript>alert('密码错误！');</script>");
            return;
        }
        else
        {
            if (!gold.isCardSell(cardID))
            {
                Response.Write("<script language=javascript>alert('此卡未出售，不允许使用！');</script>");
                return;
            }
            else if (gold.isCardUse(cardID))
            {
                Response.Write("<script language=javascript>alert('此卡已被使用！');</script>");
                return;
            }
            else
            {
                if (gold.topUpGoldCard(stuId, goldNum, cardID))
                {
                    Response.Write("<script language=javascript>alert('充值 " + goldNum + " 金币值成功！');</script>");
                    this.res();
                    return;
                }
                else
                {
                    Response.Write("<script language=javascript>alert('失败！');</script>");
                }
            }
        }
        
    }
    protected void btn_res_Click(object sender, EventArgs e)
    {
        this.res();
    }

    private void res() {
        tb_cardID.Text = "";
        tb_cardPWD.Text = "";
    }
}